<template>
    <div>
        <div class="search-content">
            <el-form ref="searchForm" :inline="true" :model="searchContent">
                <el-form-item label="店铺ID：" prop="store_id">
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.store_id"
                        placeholder="店铺ID"
                    ></el-input>
                </el-form-item>
                <el-form-item label="店铺名称：" prop="store_name">
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.store_name"
                        placeholder="店铺名称"
                    ></el-input>
                </el-form-item>
                <el-form-item label="开通时间：" prop="order_time">
                    <el-date-picker
                        v-model="searchContent.addTime"
                        type="daterange"
                        value-format="yyyy-MM-dd"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                    ></el-date-picker>
                </el-form-item>
                <el-form-item label="停用时间：" prop="order_time">
                    <el-date-picker
                        v-model="searchContent.closeTime"
                        type="daterange"
                        value-format="yyyy-MM-dd"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                    ></el-date-picker>
                </el-form-item>
                <el-form-item label="状态：" prop="status">
                    <el-select clearable v-model="searchContent.status" placeholder="合同状态">
                        <el-option value="1" label="正常"></el-option>
                        <el-option value="2" label="停用"></el-option>
                        <!-- <el-option value="Close" label="关闭"></el-option> -->
                    </el-select>
                </el-form-item>                
                <el-form-item>
                    <el-button type="primary" @click="search">搜索</el-button>
                    <el-button type="primary" @click="resetSearchData">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="search-list">
            <el-table :data="goodsList" border :height="oHeight" :fit="true">
                <!-- <el-table-column align="center" type="selection" width="55"></el-table-column> -->
                <el-table-column align="center" prop="id" label="ID" min-width="60"></el-table-column>
                <el-table-column align="center" prop="store_name" label="店铺名称" min-width="150"></el-table-column>
                <el-table-column align="center" prop="store_id" label="店铺ID" min-width="60"></el-table-column>
                <el-table-column
                    align="center"
                    prop="open_time"
                    label="开通时间"
                    min-width="160"
                ></el-table-column>
                <el-table-column
                    align="center"
                    prop="close_time"
                    label="停用时间"
                    min-width="160"
                ></el-table-column>
                <el-table-column
                    align="center"
                    prop="used_time"
                    label="质检通话总时长"
                    min-width="120"
                ></el-table-column>
                <el-table-column
                    align="center"
                    prop="status_name"
                    label="开通状态"
                    min-width="100"
                >
                </el-table-column>
                <el-table-column
                    fixed="right"
                    align="center"
                    prop="isInitiative"
                    label="操作"
                    min-width="250"
                    #default="{row}"
                >
                    <div >
                        <span style="color: #ccc" v-if="row.status_name=='停用'">停用</span>
                        <span style="color: #5790bb ;cursor: pointer;" v-else @click="changeStatus(row,'Close','停用')">停用</span>
                    </div>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group">
                    <el-button type="primary" class="btn-bottom" @click="showContent('add')">新增</el-button>
                    <!-- <el-button type="primary" class="btn-bottom" @click="expertData">导出检索数据</el-button> -->
                </div>
                <!--分页部分-->
                <div class="paginationOne">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="searchContent.currentPage"
                        :page-sizes="[10, 20, 50, 100]"
                        :page-size="searchContent.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total*1"
                    ></el-pagination>
                </div>
            </div>
        </div>
        <edit-drawer ref="editDrawer"></edit-drawer>
    </div>
</template>
<script>
import { resize } from "@/common/js/height.js";
import editDrawer from './add-inspection';
import { dateFormatter, objScreen } from "@/common/js/util";
export default {
    components: { editDrawer },
    data() {
        return {
            goodsList: [],
            oHeight: 800,
            searchContent: {
                currentPage: 1,
                pageSize: localStorage.getItem('pageSize') * 1 || 10,
                addTime:'',
                closeTime:'',
                store_id: '',
                store_name: '',
                status: '',
            },
            resetsearchContent:{
                currentPage: 1,
                pageSize: localStorage.getItem('pageSize') * 1 || 10,
                addTime:'',
                closeTime:'',
                store_id: '',
                store_name: '',
                status: '', 
            },
            searchObj: {},
            total: 0,
        };
    },
    created() {
        this.getListData();
    },
    methods: {
        showContent(type, row) {
            if (type === 'add') {
                this.$refs.editDrawer.show_dialog_fn('add',row)
            } else {
                this.$refs.editDrawer.show_dialog_fn('edit',row);
            }

        },
        changeStatus(row, status,status_name) {
            this.$http.post("/admin/dataService/index.php?act=qualityIntelligentNew&op=contractClose", {
                id: row.id,
            }).then(res => {
                if (res.code === 1) {
					row.ContractStatus = status;
                    this.$message.success(res.msg);
                    this.getListData();
                } else if (res) {
                    this.$message.error(res.msg);
                }
            }).catch(err => {
                this.$message.error(err);
            })
        },
        getListData() {
            var data = this.searchObj;
            data.currentPage = this.searchContent.currentPage;
            data.eachNum = this.searchContent.pageSize;
            this.$http.post('/admin/dataService/index.php?act=qualityIntelligentNew&op=contractList', data).then((res) => {
                if (res.code === 1) {
                    this.total = res.data.total;
                    this.goodsList = res.data.list;
                    // this._message('success', res.msg);
                    // this.getListData();
                } else {
                    this.total = 0;
                    this.goodsList = [];
                    this._message('error', res.msg);
                }
            }).catch(err => {
                this._message('error', err);
            })
        },
        search() {
            this.searchContent.currentPage = 1;
            let {addTime,closeTime,store_id, store_name,status } = this.searchContent;
            console.log(this.searchContent);
            console.log(addTime[0]);
            this.searchObj = objScreen({
                open_start: addTime[0],
                open_end: addTime[1],
                close_start: closeTime[0],
                close_end: closeTime[1],
                store_id,
                store_name,
                status
            })
            this.getListData();
        },
        resetSearchData() {
            this.$refs['searchForm'].resetFields();
            // this.searchContent = this.resetsearchContent;
            this.searchContent = {};
            this.searchObj  = {};
            this.getListData();
        },
        handleSizeChange(pageSize) {
            localStorage.setItem('pageSize', pageSize);
            this.searchContent.pageSize = pageSize;
            this.searchContent.currentPage = 1;
            this.getListData();
        },
        handleCurrentChange(page) {
            this.searchContent.currentPage = page;
            this.getListData();
        },
    },
    mounted() {
        resize(this)
    },
};
</script>
<style lang="scss" scoped>
.bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.search-content-input {
    width: 200px;
}
</style>